package com.ruoyi.floor.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;

import com.ruoyi.user.domain.HsUser;
import io.lettuce.core.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.floor.domain.HsFloor;
import com.ruoyi.floor.service.IHsFloorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼栋管理Controller
 * 
 * @author ruoyi
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/floor/floor")
public class HsFloorController extends BaseController
{
    @Autowired
    private IHsFloorService hsFloorService;

    /**
     * 查询楼栋管理列表
     */
    @PreAuthorize("@ss.hasPermi('floor:floor:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsFloor hsFloor)
    {
        startPage();
        List<HsFloor> list = hsFloorService.selectHsFloorList(hsFloor);
        return getDataTable(list);
    }

    /**
     * 导出楼栋管理列表
     */
    @PreAuthorize("@ss.hasPermi('floor:floor:export')")
    @Log(title = "楼栋管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HsFloor hsFloor)
    {
        List<HsFloor> list = hsFloorService.selectHsFloorList(hsFloor);
        ExcelUtil<HsFloor> util = new ExcelUtil<HsFloor>(HsFloor.class);
        util.exportExcel(response, list, "楼栋管理数据");
    }

    /**
     * 获取楼栋管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('floor:floor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hsFloorService.selectHsFloorById(id));
    }

    /**
     * 获取楼栋管理详细信息
     */
    @GetMapping(value = "/missionFloor")
    public AjaxResult getMissionFloor()
    {
        return success(hsFloorService.getMissionFloor());
    }

    /**
     * 获取楼栋多少栋
     */
    @GetMapping("/tree/{userXq}")
    public AjaxResult getTree(@PathVariable("userXq") String userXq)
    {
        System.out.println(userXq);
        return success(hsFloorService.getFloorTree(userXq));
    }
    /**
     * 新增楼栋管理
     */
    @PreAuthorize("@ss.hasPermi('floor:floor:add')")
    @Log(title = "楼栋管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsFloor hsFloor)
    {
        return toAjax(hsFloorService.insertHsFloor(hsFloor));
    }
    /**
     * 注册新增楼栋管理
     */

    @PostMapping("/register")
    public AjaxResult addRegisterFloor(@RequestBody HsUser hsUser)
    {
        return toAjax(hsFloorService.insertRegisterHsFloor(hsUser));
    }

    /**
     * 修改楼栋管理
     */
    @PreAuthorize("@ss.hasPermi('floor:floor:edit')")
    @Log(title = "楼栋管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsFloor hsFloor)
    {
        return toAjax(hsFloorService.updateHsFloor(hsFloor));
    }

    /**
     * 删除楼栋管理
     */
    @PreAuthorize("@ss.hasPermi('floor:floor:remove')")
    @Log(title = "楼栋管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hsFloorService.deleteHsFloorByIds(ids));
    }
}
